﻿using AJWPFAdmin.Core.Enums;
using AJWPFAdmin.Core.HardwareSDKS.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AJWPFAdmin.Core.Models.EF.Tables
{
    public partial class Device
    {
        /// <summary>
        /// 关联岗亭名称,动态赋值
        /// </summary>
        [NotMapped]
        public string WatchhouseName { get; set; }

        /// <summary>
        /// 关联通道名称,动态赋值
        /// </summary>
        [NotMapped]
        public string PassagewayName { get; set; }

        public static explicit operator DeviceInfo(Device data)
        {
            switch (data.Type)
            {
                case DeviceType.车牌识别相机_臻识:
                    return new VzCarIdentificationDevice
                    {
                        Id = data.Id,
                        Type = data.Type,
                        Code = data.Code,
                        WatchPosition = data.WatchPosition,
                        Port = data.Port,
                        IP = data.IP,
                        LoginName = data.LoginName,
                        LoginPassword = data.LoginPassword,
                        OnlyMonitor = data.OnlyMonitor,
                        EnableVideoCapture = data.EnableVideoCapture,
                        VideoDuration = data.VideoDuration,
                        AutoVideoCaptureINValue = data.AutoVideoCaptureINValue,
                        PassagewayId = data.PassagewayId,
                        WatchhouseId = data.WatchhouseId,
                        EnableIO2Alarm = data.EnableIO2Alarm,
                        IO2AlarmDelaySeconds = data.IO2AlarmDelaySeconds
                    };
                case DeviceType.高频读头:
                    return new SioReaderDevice
                    {
                        Id = data.Id,
                        Type = data.Type,
                        Code = data.Code,
                        WatchPosition = data.WatchPosition,
                        Port = data.Port,
                        IP = data.IP,
                        LoginName = data.LoginName,
                        LoginPassword = data.LoginPassword,
                        PassagewayId = data.PassagewayId,
                        WatchhouseId = data.WatchhouseId,
                        SerialPort = data.SerialPort
                    };
                case DeviceType.监控相机_海康:
                    return new HIKVisionDevice
                    {
                        Id = data.Id,
                        Type = data.Type,
                        WatchPosition = data.WatchPosition,
                        Code = data.Code,
                        Port = data.Port,
                        IP = data.IP,
                        LoginName = data.LoginName,
                        LoginPassword = data.LoginPassword,
                        OnlyMonitor = data.OnlyMonitor,
                        PassagewayId = data.PassagewayId,
                        WatchhouseId = data.WatchhouseId,
                    };
                default:
                    return new DeviceInfo
                    {
                        Id = data.Id,
                        Type = data.Type,
                        WatchPosition = data.WatchPosition,
                        Code = data.Code,
                        Port = data.Port,
                        IP = data.IP,
                        LoginName = data.LoginName,
                        LoginPassword = data.LoginPassword,

                        OnlyMonitor = data.OnlyMonitor,
                        SerialPort = data.SerialPort,
                        PassagewayId = data.PassagewayId,
                        WatchhouseId = data.WatchhouseId,
                    };
            }

        }

        public string GetDefaultRTSPUrl()
        {
            var result = string.Empty;
            switch (Type)
            {
                case Enums.DeviceType.车牌识别相机_臻识:
                    result = $"rtsp://{IP}:8557/sub_stream_1";
                    break;
                case Enums.DeviceType.监控相机_海康:
                    result = $"rtsp://{LoginName}:{LoginPassword}@{IP}:554/h264/ch1/sub/av_stream";
                    break;
                case Enums.DeviceType.高频读头:
                    break;
                default:
                    break;
            }
            return result;
        }

    }
}
